/**
 * 系统权限接口
 */
import {http, baseURL} from '../conf/index';
import {httpJ } from '../conf/index-json'
import qs from 'qs';

/***********************************  菜单管理   ************************************/
// 添加菜单接口
export const addMenu = (params = {}) => {
  return http.post(`${baseURL}/auth_resource/save`, qs.stringify(params)).then(res => res.data)
};

// 编辑菜单接口
export const modifyMenu = (params = {}) => {
  return http.post(`${baseURL}/auth_resource/modify`, qs.stringify(params)).then(res => res.data)
};

// 获取菜单列表(Json)
export const getJsonMenuList = (params = {}) => {
  return http.get(`${baseURL}/api/auth/auth_resource/query_all`, {params}).then(res => res.data)
};

// 获取菜单列表
export const getMenuList = (params = {}) => {
  return http.get(`${baseURL}/auth_resource/query_list`, {params}).then(res => res.data)
};

// 获取菜单详情
export const getMenuInfo = (params = {}) => {
  return http.get(`${baseURL}/auth_resource/get_one`, {params}).then(res => res.data)
};

// 删除菜单
export const deleteMenu = (params = {}) => {
  return http.post(`${baseURL}/auth_resource/delete`, qs.stringify(params)).then(res => res.data)
};

// 添加菜单按钮权限
export const addBtnPermissions = (params = {}) => {
  return http.post(`${baseURL}/auth_resource/save_button`, qs.stringify(params)).then(res => res.data)
};


/***********************************  角色管理   ************************************/
// 获取角色列表
export const getRoleList = (params = {}) => {
  return http.get(`${baseURL}/api/auth/role/query_list`, {params}).then(res => res.data)
};

// 添加角色
export const addRole = (params = {}) => {
  return http.post(`${baseURL}/api/auth/role/saveForUnit`, qs.stringify(params)).then(res => res.data)
};

// 编辑角色列表
export const modifyRole = (params = {}) => {
  return http.post(`${baseURL}/api/auth/role/modifyForUnit`, qs.stringify(params)).then(res => res.data)
};

// 获取角色详情
export const getRoleInfo = (params = {}) => {
  return http.get(`${baseURL}/api/auth/role/get_one`, {params}).then(res => res.data)
};

// 删除角色
export const deleteRole = (params = {}) => {
  return http.post(`${baseURL}/api/auth/role/deleteForUnit`, qs.stringify(params)).then(res => res.data)
};

// 编辑角色权限
export const modifyRolePermission = (params = {}) => {
  return http.post(`${baseURL}/api/auth/role_resource/save`, qs.stringify(params)).then(res => res.data)
};

// 获取角色对应权限
export const getRolePermission = (params = {}) => {
  return http.get(`${baseURL}/api/auth/role_resource/get_resource`, {params}).then(res => res.data)
};


/***********************************  用户管理   ************************************/
// 获取用户列表
export const getUserList = (params = {}) => {
  return http.get(`${baseURL}/api/auth/auth_user/query_list`, {params}).then(res => res.data)
};

// 添加用户
export const addUser = (params = {}) => {
  return http.post(`${baseURL}/api/auth/auth_user/save`, qs.stringify(params)).then(res => res.data)
};

// 编辑用户列表
export const modifyUser = (params = {}) => {
  return http.post(`${baseURL}/api/auth/auth_user/modify`, qs.stringify(params)).then(res => res.data)
};

// 获取用户详情
export const getUserInfo = (params = {}) => {
  return http.get(`${baseURL}/api/auth/auth_user/get_one`, {params}).then(res => res.data)
};

// 删除用户
export const deleteUser = (params = {}) => {
  return http.post(`${baseURL}/api/auth/auth_user/delete`, qs.stringify(params)).then(res => res.data)
};

// 用户关联角色
export const userRelevanceRole = (params = {}) => {
  return http.post(`${baseURL}/api/auth/user_role/save`, qs.stringify(params)).then(res => res.data)
};

// 通过角色获取权限
export const getPermissionForRoleId = (params = {}) => {
  return httpJ.post(`${baseURL}/api/auth/auth_resource/roles_tree`, params).then(res => res.data)
};
// 重置密码
export const resetUserPassword = (params = {}) => {
  return httpJ.post(`${baseURL}/api/auth/auth_user/reset_password`, params).then(res => res.data)
};
// 管理员交接
export const handoverUser = (params = {}) => {
  return httpJ.post(`${baseURL}/api/auth/auth_user/handover`, params).then(res => res.data)
};
/***********************************  用户登录   ************************************/
// 获取系统版本号接口
export const getVersionNo = (params = {}) => {
  return http.get(`${baseURL}/api/auth/system/version`,{params}).then(res => res.data)
};
// 登录
export const login = (params = {}) => {
  return http.post(`${baseURL}/api/auth/auth_user/login`, qs.stringify(params)).then(res => res.data)
};

// 获取用户信息
export const getUserBaseInfo = (params = {}) => {
  return http.get(`${baseURL}/api/auth/auth_user/token_info`, {params}).then(res => res.data)
};

// 修改个人密码
export const modifyUserInfo = (params = {}) => {
  return http.post(`${baseURL}/api/auth/auth_user/modify_info`, qs.stringify(params)).then(res => res.data)
};

// 退出登录
export const loginOut = (params = {}) => {
  return http.post(`${baseURL}/api/auth/auth_user/login_out`, qs.stringify(params)).then(res => res.data)
};
//  改变用户状态
export const modifyUserStatus = (params = {}) => {
  return httpJ.post(`${baseURL}/api/auth/auth_user/reset_status`, params).then(res => res.data)
};
// 用户权限变更
export const userRoleModify = (params = {}) => {
  return http.get(`${baseURL}/auth/auth_token/delete_message`, {params}).then(res => res.data)
};


// 删除图片
export const deleteImg = (params = {}) => {
  return http.post(`${baseURL}/material/delete_img`, qs.stringify(params)).then(res => res.data)
};


// 单点登录
export const removeLogin = (params = {}) => {
  return http.post(`${baseURL}/api/auth/auth_user/remote_login`, qs.stringify(params)).then(res => res.data)
};